{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.7.9 64-bit (system)"
  },
  "metadata": {
   "interpreter": {
    "hash": "e79309c8f6622ce988b04c24bb6d5b54a89cf65be865511eaf3b861e4b3f791f"
   }
  },
  "interpreter": {
   "hash": "e79309c8f6622ce988b04c24bb6d5b54a89cf65be865511eaf3b861e4b3f791f"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# 导入库"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "source": [
    "import efinance as ef"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 使用例子"
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 获取单只基金基本信息"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "source": [
    "ef.fund.get_base_info('161725')"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "基金代码                                 161725\n",
       "基金简称                         招商中证白酒指数(LOF)A\n",
       "成立日期                             2015-05-27\n",
       "涨跌幅                                     0.8\n",
       "最新净值                                 1.2914\n",
       "基金公司                                   招商基金\n",
       "净值更新日期                           2021-08-13\n",
       "简介        产品特色：布局白酒领域的指数基金，历史业绩优秀，外资偏爱白酒板块。\n",
       "dtype: object"
      ]
     },
     "metadata": {},
     "execution_count": 2
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 获取多只基金基本信息"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "source": [
    "ef.fund.get_base_info(['161725','005827'])"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "processing 161725: 100%|██████████| 2/2 [00:00<00:00,  7.45it/s]"
     ]
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "     基金代码            基金简称        成立日期   涨跌幅    最新净值   基金公司      净值更新日期  \\\n",
       "0  005827       易方达蓝筹精选混合  2018-09-05 -0.04  2.5887  易方达基金  2021-08-13   \n",
       "1  161725  招商中证白酒指数(LOF)A  2015-05-27  0.80  1.2914   招商基金  2021-08-13   \n",
       "\n",
       "                                     简介  \n",
       "0  明星消费基金经理另一力作，A+H股同步布局，价值投资典范，适合长期持有。  \n",
       "1     产品特色：布局白酒领域的指数基金，历史业绩优秀，外资偏爱白酒板块。  "
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>基金代码</th>\n",
       "      <th>基金简称</th>\n",
       "      <th>成立日期</th>\n",
       "      <th>涨跌幅</th>\n",
       "      <th>最新净值</th>\n",
       "      <th>基金公司</th>\n",
       "      <th>净值更新日期</th>\n",
       "      <th>简介</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>005827</td>\n",
       "      <td>易方达蓝筹精选混合</td>\n",
       "      <td>2018-09-05</td>\n",
       "      <td>-0.04</td>\n",
       "      <td>2.5887</td>\n",
       "      <td>易方达基金</td>\n",
       "      <td>2021-08-13</td>\n",
       "      <td>明星消费基金经理另一力作，A+H股同步布局，价值投资典范，适合长期持有。</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>161725</td>\n",
       "      <td>招商中证白酒指数(LOF)A</td>\n",
       "      <td>2015-05-27</td>\n",
       "      <td>0.80</td>\n",
       "      <td>1.2914</td>\n",
       "      <td>招商基金</td>\n",
       "      <td>2021-08-13</td>\n",
       "      <td>产品特色：布局白酒领域的指数基金，历史业绩优秀，外资偏爱白酒板块。</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 3
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 获取基金历史净值信息"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "source": [
    "ef.fund.get_quote_history('161725')"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "             日期    单位净值    累计净值     涨跌幅\n",
       "0    2021-08-13  1.2914  2.9225     0.8\n",
       "1    2021-08-12  1.2812  2.9123   -1.73\n",
       "2    2021-08-11  1.3038  2.9349   -1.61\n",
       "3    2021-08-10  1.3251  2.9562    6.48\n",
       "4    2021-08-09  1.2445  2.8756    1.06\n",
       "...         ...     ...     ...     ...\n",
       "1513 2015-06-08  1.0380  1.0380  2.5692\n",
       "1514 2015-06-05  1.0120  1.0120  1.5045\n",
       "1515 2015-06-04  0.9970  0.9970      --\n",
       "1516 2015-05-29  0.9950  0.9950      --\n",
       "1517 2015-05-27  1.0000  1.0000      --\n",
       "\n",
       "[1518 rows x 4 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>单位净值</th>\n",
       "      <th>累计净值</th>\n",
       "      <th>涨跌幅</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2021-08-13</td>\n",
       "      <td>1.2914</td>\n",
       "      <td>2.9225</td>\n",
       "      <td>0.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2021-08-12</td>\n",
       "      <td>1.2812</td>\n",
       "      <td>2.9123</td>\n",
       "      <td>-1.73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2021-08-11</td>\n",
       "      <td>1.3038</td>\n",
       "      <td>2.9349</td>\n",
       "      <td>-1.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2021-08-10</td>\n",
       "      <td>1.3251</td>\n",
       "      <td>2.9562</td>\n",
       "      <td>6.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2021-08-09</td>\n",
       "      <td>1.2445</td>\n",
       "      <td>2.8756</td>\n",
       "      <td>1.06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1513</th>\n",
       "      <td>2015-06-08</td>\n",
       "      <td>1.0380</td>\n",
       "      <td>1.0380</td>\n",
       "      <td>2.5692</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1514</th>\n",
       "      <td>2015-06-05</td>\n",
       "      <td>1.0120</td>\n",
       "      <td>1.0120</td>\n",
       "      <td>1.5045</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1515</th>\n",
       "      <td>2015-06-04</td>\n",
       "      <td>0.9970</td>\n",
       "      <td>0.9970</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1516</th>\n",
       "      <td>2015-05-29</td>\n",
       "      <td>0.9950</td>\n",
       "      <td>0.9950</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1517</th>\n",
       "      <td>2015-05-27</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1518 rows × 4 columns</p>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 获取多只基金净值估算信息"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "source": [
    "ef.fund.get_realtime_increase_rate(['161725','005827'])"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "     基金代码            基金名称       PDATE     NAV  ACCNAV  NAVCHGRT     GSZ  \\\n",
       "0  161725  招商中证白酒指数(LOF)A  2021-08-13  1.2914  2.9225      0.80  1.2911   \n",
       "1  005827       易方达蓝筹精选混合  2021-08-13  2.5887  2.5887     -0.04  2.5846   \n",
       "\n",
       "   估算涨跌幅              估算时间 NEWPRICE CHANGERATIO     ZJL               HQDATE  \\\n",
       "0   0.77  2021-08-13 15:00    1.293        0.47 -0.1239  2021-08-13 15:34:03   \n",
       "1  -0.20  2021-08-13 15:00       --          --      --                   --   \n",
       "\n",
       "   ISHAVEREDPACKET  \n",
       "0            False  \n",
       "1            False  "
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>基金代码</th>\n",
       "      <th>基金名称</th>\n",
       "      <th>PDATE</th>\n",
       "      <th>NAV</th>\n",
       "      <th>ACCNAV</th>\n",
       "      <th>NAVCHGRT</th>\n",
       "      <th>GSZ</th>\n",
       "      <th>估算涨跌幅</th>\n",
       "      <th>估算时间</th>\n",
       "      <th>NEWPRICE</th>\n",
       "      <th>CHANGERATIO</th>\n",
       "      <th>ZJL</th>\n",
       "      <th>HQDATE</th>\n",
       "      <th>ISHAVEREDPACKET</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>161725</td>\n",
       "      <td>招商中证白酒指数(LOF)A</td>\n",
       "      <td>2021-08-13</td>\n",
       "      <td>1.2914</td>\n",
       "      <td>2.9225</td>\n",
       "      <td>0.80</td>\n",
       "      <td>1.2911</td>\n",
       "      <td>0.77</td>\n",
       "      <td>2021-08-13 15:00</td>\n",
       "      <td>1.293</td>\n",
       "      <td>0.47</td>\n",
       "      <td>-0.1239</td>\n",
       "      <td>2021-08-13 15:34:03</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>005827</td>\n",
       "      <td>易方达蓝筹精选混合</td>\n",
       "      <td>2021-08-13</td>\n",
       "      <td>2.5887</td>\n",
       "      <td>2.5887</td>\n",
       "      <td>-0.04</td>\n",
       "      <td>2.5846</td>\n",
       "      <td>-0.20</td>\n",
       "      <td>2021-08-13 15:00</td>\n",
       "      <td>--</td>\n",
       "      <td>--</td>\n",
       "      <td>--</td>\n",
       "      <td>--</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 获取单只基金最新季度公开持仓股票行业分布信息"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "source": [
    "\r\n",
    "ef.fund.get_industry_distribution('161725')"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "      基金代码              行业名称   持仓比例        公布日期              市值\n",
       "0   161725               制造业  93.07  2021-06-30  6492580.019556\n",
       "1   161725               金融业   0.01  2021-06-30      485.060688\n",
       "2   161725          农、林、牧、渔业      0  2021-06-30        0.585078\n",
       "3   161725  电力、热力、燃气及水生产和供应业      0  2021-06-30        1.302039\n",
       "4   161725               建筑业      0  2021-06-30        2.537137\n",
       "5   161725            批发和零售业      0  2021-06-30        5.888394\n",
       "6   161725   信息传输、软件和信息技术服务业      0  2021-06-30      157.037536\n",
       "7   161725     水利、环境和公共设施管理业      0  2021-06-30        4.443833\n",
       "8   161725                教育      0  2021-06-30        1.626203\n",
       "9   161725        科学研究和技术服务业      0  2021-06-30        48.30805\n",
       "10  161725               采矿业     --  2021-06-30              --\n",
       "11  161725       交通运输、仓储和邮政业     --  2021-06-30              --\n",
       "12  161725          租赁和商务服务业     --  2021-06-30              --\n",
       "13  161725            住宿和餐饮业     --  2021-06-30              --\n",
       "14  161725              房地产业     --  2021-06-30              --\n",
       "15  161725     居民服务、修理和其他服务业     --  2021-06-30              --\n",
       "16  161725           卫生和社会工作     --  2021-06-30              --\n",
       "17  161725         文化、体育和娱乐业     --  2021-06-30              --\n",
       "18  161725                综合     --  2021-06-30              --\n",
       "19  161725                合计  93.08  2021-06-30  6493286.808514"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>基金代码</th>\n",
       "      <th>行业名称</th>\n",
       "      <th>持仓比例</th>\n",
       "      <th>公布日期</th>\n",
       "      <th>市值</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>161725</td>\n",
       "      <td>制造业</td>\n",
       "      <td>93.07</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>6492580.019556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>161725</td>\n",
       "      <td>金融业</td>\n",
       "      <td>0.01</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>485.060688</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>161725</td>\n",
       "      <td>农、林、牧、渔业</td>\n",
       "      <td>0</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>0.585078</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>161725</td>\n",
       "      <td>电力、热力、燃气及水生产和供应业</td>\n",
       "      <td>0</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>1.302039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>161725</td>\n",
       "      <td>建筑业</td>\n",
       "      <td>0</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>2.537137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>161725</td>\n",
       "      <td>批发和零售业</td>\n",
       "      <td>0</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>5.888394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>161725</td>\n",
       "      <td>信息传输、软件和信息技术服务业</td>\n",
       "      <td>0</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>157.037536</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>161725</td>\n",
       "      <td>水利、环境和公共设施管理业</td>\n",
       "      <td>0</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>4.443833</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>161725</td>\n",
       "      <td>教育</td>\n",
       "      <td>0</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>1.626203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>161725</td>\n",
       "      <td>科学研究和技术服务业</td>\n",
       "      <td>0</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>48.30805</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>161725</td>\n",
       "      <td>采矿业</td>\n",
       "      <td>--</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>161725</td>\n",
       "      <td>交通运输、仓储和邮政业</td>\n",
       "      <td>--</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>161725</td>\n",
       "      <td>租赁和商务服务业</td>\n",
       "      <td>--</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>161725</td>\n",
       "      <td>住宿和餐饮业</td>\n",
       "      <td>--</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>161725</td>\n",
       "      <td>房地产业</td>\n",
       "      <td>--</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>161725</td>\n",
       "      <td>居民服务、修理和其他服务业</td>\n",
       "      <td>--</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>161725</td>\n",
       "      <td>卫生和社会工作</td>\n",
       "      <td>--</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>161725</td>\n",
       "      <td>文化、体育和娱乐业</td>\n",
       "      <td>--</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>161725</td>\n",
       "      <td>综合</td>\n",
       "      <td>--</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>161725</td>\n",
       "      <td>合计</td>\n",
       "      <td>93.08</td>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>6493286.808514</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 6
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 更多使用例子详见文档 [efinance-docs](https://efinance.readthedocs.io/)\r\n"
   ],
   "metadata": {}
  }
 ]
}